package com.example.demojenkins.config;

import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

@Component
public class CustomStringRedisSerializer implements RedisSerializer<String> {

    public final Charset charset ;

    public CustomStringRedisSerializer() {
        this(StandardCharsets.UTF_8);
    }

    public CustomStringRedisSerializer(Charset charset) {
        Assert.notNull(charset, "Charset must not be null!");
        this.charset = charset;
    }

    @Override
    public byte[] serialize(String s) throws SerializationException {
        return ("Lz:"+s).getBytes(charset);
    }

    @Override
    public String deserialize(byte[] bytes) throws SerializationException {
        return null;
    }
}
